define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        METHOD = ALL.METHOD,
        Dialog = ALL.Dialog,
        Init = ALL.Init;

    var _vm = Init.initVue({
        data : {
            sn : '',
            month : '',
            list : [],
            cur : 1,
            all : 0,
            search : false
        },
        methods: {
            reSearch : function() {
                this.search = true;
                this.getData(1);
            },
            back : function() {
                var ids = [];
                this.list.forEach(function(v){
                    if (v.selected) {
                        ids.push(v.id);
                    }
                });
                if (ids.length == 0) {
                    METHOD.alert("请先选择");
                    return;
                }
                METHOD.loading.show();
                METHOD.ajax("finance/benefit/create",{ids:ids.join(",")}, {type:"post"}).done(function(json){
                    METHOD.loading.hide();
                    METHOD.alert("返还成功");
                    _vm.getData(_vm.cur);
                }).fail(function(){
                    METHOD.loading.hide();
                });
            },
            reset : function() {
                this.search = false;
                this.month = '';
                this.sn = '';
            },
            getData : function(n) {
                var obj = {
                    page : n,
                    num : 10,
                    month : _vm.month,
                    sn : _vm.sn,
                    status : 1
                };
                METHOD.loading.show();
                METHOD.ajax("finance/benefit/get_list",obj).done(function(json){
                    METHOD.loading.hide();
                    json.data.forEach(function(v){
                        v.selected = false;
                    });
                    _vm.list = json.data;
                    _vm.all = json.page.pages;
                }).fail(function(){
                    METHOD.loading.hide();
                });
            }
        },
        computed: {
            allSelected : {
                get: function() {
                    var inOn;
                    if(this.list.length > 0) {
                        isOn = this.list.every(function(v) {
                            if (v.selected === true) {
                                return true;
                            } else {
                                return false;
                            }
                        });
                    }
                    return isOn ? true : false;
                },
                set: function(n){
                    this.list.forEach(function(v){ v.selected = n; });
                }
            }
        }
    });

    _vm.getData(1);
});

